package com.wondersgroup.framework.sample.component.chart.action;

import com.wondersgroup.framework.core.web.struts2.action.BaseAjaxAction;
import com.wondersgroup.framework.sample.component.chart.util.ColorHelper;
import com.wondersgroup.framework.util.ChartUtils;
import com.wondersgroup.framework.util.chartmodel.MultiChartModel;
import com.wondersgroup.framework.util.chartmodel.MultiDataModel;
import com.wondersgroup.framework.util.chartmodel.SingleChartModel;

import java.util.ArrayList;
import java.util.List;

public class ChartAction extends BaseAjaxAction {

	public void loadSingledata() throws Exception {
		getServletResponse().setContentType("text/html;charset=utf-8");
		List<SingleChartModel> list = new ArrayList<SingleChartModel>();
		for (int i = 1; i <= 5; ++i) {
			SingleChartModel model = new SingleChartModel();
			model.setName("column" + i); // 名称
			String s = (Math.random() * 1000.0D) + "";
			s.substring(0, s.indexOf("."));
			model.setValue(s); // 值
			model.setColor(ColorHelper.getColor()); // 颜色
			model.setCode(i + "");
			list.add(model);
		}
		ChartUtils.writeXMLDataSingle(list, false, "to_showSingle");
	}

	public void loadMultidata() throws Exception {
		getServletResponse().setContentType("text/html;charset=utf-8");
		List<String> nameList = new ArrayList<String>();
		List<String> codeList = new ArrayList<String>();
		for (int i = 1; i <= 4; ++i) {
			nameList.add("multicolumn" + i); // 名称列表
			codeList.add(i + "");
		}
		List<MultiDataModel> mulitList = new ArrayList<MultiDataModel>();
		for (int j = 1; j <= 3; ++j) {
			MultiDataModel multiModel = new MultiDataModel();
			multiModel.setName("multi" + j); // 名称
			multiModel.setColor(ColorHelper.getColor()); // 颜色
			multiModel.setCode(j + "");
			List<String> valueList = new ArrayList<String>();
			for (int k = 1; k <= 4; ++k) {
				String s = (Math.random() * 1000.0D) + "";
				s.substring(0, s.indexOf("."));
				valueList.add(s);
			}
			multiModel.setValues(valueList); // 值列表
			mulitList.add(multiModel);
		}
		MultiChartModel multichartmodel = new MultiChartModel();
		multichartmodel.setZName(nameList);
		multichartmodel.setZCode(codeList);
		multichartmodel.setMultiData(mulitList);
		ChartUtils.writeXMLDataMulti(multichartmodel, true, "to_showMulti");
	}

	public void loadcolumnline() throws Exception {
		getServletResponse().setContentType("text/html;charset=utf-8");
		List<String> nameList = new ArrayList<String>();
		List<String> codeList = new ArrayList<String>();
		for (int i = 1; i <= 4; ++i) {
			nameList.add("multicolumn" + i); // 名称列表
			codeList.add(i + "");
		}

		List<MultiDataModel> mulitList = new ArrayList<MultiDataModel>();
		for (int j = 1; j <= 3; ++j) {
			MultiDataModel multiModel = new MultiDataModel();
			multiModel.setName("multi" + j); // 名称
			if (j == 1) {
				multiModel.setParentYAxis("S"); // 折线
			}

			multiModel.setColor(ColorHelper.getColor()); // 颜色
			multiModel.setCode(j + "");
			List<String> valueList = new ArrayList<String>();
			for (int k = 1; k <= 4; ++k) {
				String s = (Math.random() * 1000.0D) + "";
				s.substring(0, s.indexOf("."));
				valueList.add(s);
			}
			multiModel.setValues(valueList);
			mulitList.add(multiModel);
		}
		MultiChartModel multichartmodel = new MultiChartModel();
		multichartmodel.setZName(nameList);
		multichartmodel.setZCode(codeList);
		multichartmodel.setMultiData(mulitList);
		ChartUtils.writeXMLDataMulti(multichartmodel, true, "to_showMulti");
	}
}